package com.leetcode.LC;

import java.util.Stack;

public class LC1290 {
    public int getDecimalValue(ListNode head) {
        //借助栈，先存入栈中，然后取出

        Stack<Integer> stack = new Stack<>();
        ListNode tmp = head;
        while (tmp != null) {
            stack.push(tmp.val);
            tmp=tmp.next;
        }
        int sum=0,i=0;
        while (stack.size()>=1){
            sum+=(stack.pop()*Math.pow(2,i++));
        }

        return sum;

    }
}
